The present paper outlines theoretical principles of the post-Newtonian mechanics in the expanding universe. It is based upon the gauge-invariant theory of the Lagrangian perturbations of cosmological manifold caused by an isolated astronomical N-body system. We postulate that the background manifold is described by Friedman-Lemaitre-Robertson-Walker (FLRW) metric governed by two primary components - the dark matter and the dark energy. The dark matter is treated as an ideal fluid. The dark energy is described by a single scalar field with a potential which is hold unspecified as long as the theory permits. The Lagrangian of the dark matter and that of the scalar field are formulated in terms of the field variables. We use variational calculus to derive the gauge-invariant field equations of the post-Newtonian celestial mechanics of an isolated astronomical system in an expanding universe. These equations generalize the field equations of the post-Newtonian theory in asymptotically-flat spacetime by taking into account the cosmological effects explicitly. We introduce a new cosmological gauge which generalizes the harmonic gauge of the post-Newtonian theory in asymptotically-flat spacetime. This gauge significantly simplifies the gravitational field equations and allows finding out the approximations where the field equations can be fully decoupled and solved analytically. The residual gauge freedom is explored. The results of the present paper can be useful in the solar system for calculating more precise ephemerides of the solar system bodies on extremely long time intervals, in galactic astronomy to study the dynamics of clusters of galaxies, and in gravitational wave astronomy for discussing the impact of cosmology on generation and propagation of gravitational waves emitted by coalescing binaries and/or merging galactic nuclei.